import matplotlib.pyplot as plt
import sqlite3 as sql
def mkdir(path):
    import os
    path = path.strip()
    path = path.rstrip("\\")
    isExists = os.path.exists(path)
    if not isExists:
        os.makedirs(path)
        return True
    else:
        return False
lst = []
index = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
col = ['','#003f5c','#2f4b7c','#665191','#a05195','#d45087','#f95d6a','#ff7c43', '#ef9c00','#efa000','#ffa600']
db = sql.connect('task-db')
cursor = db.cursor()
for j in index:
    for k in index:
        cursor.execute("SELECT * FROM task WHERE pc>="+ str(j)+" AND pc <=" + str(j + 0.05) + " AND pm>="+ str(k)+" AND pm <=" + str(k + 0.05) + " AND itertime < 200;")
        result = cursor.fetchall()
        x = [[],[],[],[],[],[],[],[],[],[],[]]
        y = [[],[],[],[],[],[],[],[],[],[],[]]
        result = list(result)
        for i in result:
            x[i[2] // 10].append(i[3])
            y[i[2] // 10].append(i[4])
        plt.cla()
        for i in range(1, 10):
            plt.plot(x[i], y[i],color=col[i],label=i*10)
        plt.legend()
        plt.rcParams['font.sans-serif']=['SimHei'] 
        plt.title("pc=" + str(j) + " pm = " + str(k) +":the affect caused by pn")
        plt.xlabel("itertime")
        plt.ylabel("result")
        try :
            plt.savefig("./pictures/"+str(j)+"/"+str(k)+".png")
        except FileNotFoundError:
            mkdir("./pictures/"+str(j))
            plt.savefig("./pictures/"+str(j)+"/"+str(k)+".png")
        plt.clf()

